<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xmlns:t="http://myfaces.apache.org/tomahawk"
	xmlns:ap="http://aplikata.com/facelets" template="/pages/template/main-layout.xhtml">

	<ui:define name="content">
		<t:saveState value="#{evokPatientBean.qyPatientName}" />
		<t:saveState value="#{evokPatientBean.patient}" />
		<t:saveState value="#{evokPatientBean.birthRegionId}" />
		<t:saveState value="#{evokPatientBean.birthCityId}" />
		<t:saveState value="#{evokPatientBean.birthCityList}" />

		<t:saveState value="#{evokPatientBean.liveRegionId}" />
		<t:saveState value="#{evokPatientBean.liveCityId}" />
		<t:saveState value="#{evokPatientBean.liveCityList}" />

		<h:panelGrid columns="2" cellpadding="3" width="100%" columnClasses="width30,width70">
			<h:panelGrid width="100%">
				<p:panel header="#{msgs.table_querycon}">
					<h:panelGrid columns="2" cellpadding="5" width="100%">
						<h:outputLabel for="patientname" value="#{msgs.default_name_surname}" />
						<p:autoComplete completeMethod="#{evokPatientBean.completeQueryName}" id="patientname"
							size="40" value="#{evokPatientBean.qyPatientName}" forceSelection="true" minQueryLength="3">
							<p:ajax event="itemSelect" listener="#{evokPatientBean.selectPatientName}"
								update=":messages,:mainform:patientlist,:mainform:pnlinfo" />
						</p:autoComplete>
					</h:panelGrid>
					<f:facet name="footer">
						<p:commandButton value="#{msgs.button_reset}" icon="ui-icon-arrowrefresh-1-n"
							autoSubmit="false" actionListener="#{evokPatientBean.addPatient}" process="@this"
							update="pnlinfo,patientname,patientlist" />
					</f:facet>
				</p:panel>

				<p:dataTable var="lo" id="patientlist" value="#{evokPatientBean.patientModel}" emptyMessage=""
					selectionMode="single" rowKey="#{lo.id}" widgetVar="wdgPatientList">
					<p:ajax event="rowSelect" listener="#{evokPatientBean.selectPatient}"
						update=":mainform:pnlinfo" />
					<p:column headerText="#{msgs.default_name_surname}">
						<h:outputText value="#{lo.surname} #{lo.name}" />
					</p:column>
				</p:dataTable>
				<br/>	
				<p:panelGrid width="100%" columns="1">
					<h:outputText value="#{msgs.evok_patient_remark}" style="color:red;"/>
				</p:panelGrid>
			</h:panelGrid>

			<h:panelGrid width="100%" id="pnlinfo">
				<h:panelGroup style="float:right;">
					<p:commandButton value="#{msgs.button_submit}" icon="ui-icon-disk" 
						actionListener="#{evokPatientBean.submitPatient}"
						process="paitentInfo:basicinfo,paitentInfo:patientContact,paitentInfo:patientspec,@this"
						oncomplete="wdgContactList.unselectAllRows();"
						update=":messages, :mainform:patientlist,pnlinfo">
					</p:commandButton>

					<h:outputText value="&#160;&#160;" escape="false" />
					<p:commandButton value="#{msgs.button_print}" icon="ui-icon-print"
						rendered="#{!evokPatientBean.readonly}" ajax="false" immediate="true"
						actionListener="#{evokPatientBean.generatePdfReport}" />

				</h:panelGroup>
				<h:inputHidden value="#{evokPatientBean.patient.id}" />

				<p:tabView id="paitentInfo" activeIndex="#{evokPatientBean.tabIndex}">
					<p:tab title="#{msgs.default_basic_data}" id="basicinfo">
						<ui:include src="patient_basic.xhtml" />
					</p:tab>

					<p:tab title="#{msgs.default_contact_data}" id="patientContact"
						rendered="#{evokPatientBean.domainPatient.id != null and evokPatientBean.domainPatient.id > 0  }">
						<ui:include src="patient_contact.xhtml" />
					</p:tab>

					<p:tab title="#{msgs.evok_patient_specific}"
						rendered="#{evokPatientBean.domainPatient.id != null and evokPatientBean.domainPatient.id > 0  }">
						<ap:dynamicCategoryTable value="#{evokPatientBean.pnList}" id="patientspec" />
					</p:tab>

					<p:tab title="#{msgs.evok_patient_contactPerson}"
						rendered="#{evokPatientBean.domainPatient.id != null and evokPatientBean.domainPatient.id > 0  }">
						<ui:include src="patient_contact_person.xhtml" />
					</p:tab>

					<p:tab title="#{msgs.evok_patient_document}" id="patientDocuments"
						rendered="#{evokPatientBean.domainPatient.id != null and evokPatientBean.domainPatient.id > 0  }">
						<ui:include src="patient_attachement.xhtml" />
					</p:tab>
				</p:tabView>
			</h:panelGrid>
		</h:panelGrid>
	</ui:define>

	<ui:define name="dialog">
		<h:panelGrid>
			<p:confirmDialog message="#{msgs.info_sure_delete}" width="200" showEffect="explode"
				hideEffect="explode" header="POZOR" severity="alert" widgetVar="confirmContactPerson"
				modal="true">

				<p:commandButton value="DA" update=":mainform:paitentInfo:pnlContactPerson,:messages"
					immediate="true"
					actionListener="#{evokPatientBean.deleteContactPerson}"
					oncomplete="confirmContactPerson.hide()" />

				<p:commandButton value="NE" onclick="confirmContactPerson.hide()" type="button" />
			</p:confirmDialog>

			<p:confirmDialog message="#{msgs.info_sure_delete}" width="200" showEffect="explode"
				hideEffect="explode" header="#{msgs.default_alert}" severity="alert"
				widgetVar="confirmAttachementDelete" modal="true" id="deleteAttachementD">

				<p:commandButton value="#{msgs.button_and}"
					immediate="true"
					update=":messages,:mainform:paitentInfo:attachementPanelGrid"
					actionListener="#{evokPatientAttachementBean.deleteAction}"
					oncomplete="confirmAttachementDelete.hide()" />

				<p:commandButton value="#{msgs.button_not}" onclick="confirmAttachementDelete.hide()"
					type="button" />
			</p:confirmDialog>
		</h:panelGrid>
	</ui:define>
</ui:composition>
